package project.Util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtil {
    public static String genUtil(Map<String, Object> claim) {
        return JWT.create()
                .withClaim("user", claim)
                .withExpiresAt(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24))
                .sign(Algorithm.HMAC256("damn"));
    }

    public static Map<String, Object> getToken(String token) {
        return JWT.require(Algorithm.HMAC256("damn")).build()
                .verify(token)
                .getClaims()
                .get("user")
                .asMap();
    }
}
